<?php
if(isset($_GET['user_id']) && is_numeric($_GET['user_id']))
	$uid=$_GET['user_id'];
else
	$uid=$this->user_id;
	
$edit=false;
if($uid==$this->user_id)
	$edit=true;

$this->sql->query("SELECT us.user_name, ally_tag FROM ".$this->sql->getpre()."users us LEFT JOIN ".$this->sql->getpre()."ally ON user_ally=ally_id WHERE us.user_id=$uid;");
$this->sql->fetch_assoc();
$this->addTitle($lang['users']['fleet_title']." - ".$this->sql->row["user_name"]);



echo "<h3>".$lang['users']['fleet_title']." <span style=\"font-size:80%\">von ".$this->sql->row["user_name"]." <span style=\"font-size:80%\">(".$this->sql->row["ally_tag"].")"."</span></span></h3>";
echo "\n";

echo "
<a href=\"?com=201&user_id=$uid\"><img src=\"images/icon_fleet.png\" /></a>
<a href=\"?com=200&user_id=$uid\"><img src=\"images/icon_planeten.png\" /></a>
<a href=\"?com=203&user_id=$uid\"><img src=\"images/icon_statts.png\" /></a>
<a href=\"?com=202&user_id=$uid\"><img src=\"images/icon_forschung.png\" /></a><br /><br />";

if($edit && isset($_POST['fleet'])){
	//echo "update";
	//echo "<pre>";
	//print_r($_POST);
	//echo "</pre>";

	$sql="UPDATE 
		".$this->sql->getpre()."fleet
	SET
		fleet_kt = '".$_POST['fleet'][$lang['fleet']['kt']]."',
		fleet_gt = '".$_POST['fleet'][$lang['fleet']['gt']]."',
		fleet_lj = '".$_POST['fleet'][$lang['fleet']['lj']]."',
		fleet_sj = '".$_POST['fleet'][$lang['fleet']['sj']]."',
		fleet_xer = '".$_POST['fleet'][$lang['fleet']['xer']]."',
		fleet_ss = '".$_POST['fleet'][$lang['fleet']['ss']]."',
		fleet_sk = '".$_POST['fleet'][$lang['fleet']['sk']]."',
		fleet_ks = '".$_POST['fleet'][$lang['fleet']['ks']]."',
		fleet_recy = '".$_POST['fleet'][$lang['fleet']['recy']]."',
		fleet_spio = '".$_POST['fleet'][$lang['fleet']['spio']]."',
		fleet_bomb = '".$_POST['fleet'][$lang['fleet']['bomb']]."',
		fleet_zer = '".$_POST['fleet'][$lang['fleet']['zer']]."',
		fleet_tod = '".$_POST['fleet'][$lang['fleet']['tod']]."'
	WHERE 
		user_id=".$uid.";";
	
	$this->sql->queryS($sql);
	
	echo "<span style=\"color:green;\">".$lang['admin']['info_saved']."</span>";
}

if($uid == $this->user_id){
	$lines="WHERE us.user_id=".$this->user_id;
}else{
	$sql_reduce="\n\tAND\n\tal.show_planeten=1";
	if(in_array($this->user_group, $restrict_ally_group) or in_array($this->user_id, $restrict_ally_user))
		$sql_reduce="\n\tAND\n\tal.ally_id=".$this->user_ally_id;
	if(in_array($this->user_group, $restrict_user_group) or in_array($this->user_id, $restrict_user_user))
		$sql_reduce="\n\tAND\n\tus.user_id=".$this->user_id;
	
	$lines="WHERE us.user_id=$uid $sql_reduce";
}

$sql="SELECT 
	fl.fleet_kt AS '".$lang['fleet']['kt']."',
	fl.fleet_gt AS '".$lang['fleet']['gt']."',
	fl.fleet_lj AS '".$lang['fleet']['lj']."',
	fl.fleet_sj AS '".$lang['fleet']['sj']."',
	fl.fleet_xer AS '".$lang['fleet']['xer']."',
	fl.fleet_ss AS '".$lang['fleet']['ss']."',
	fl.fleet_sk AS '".$lang['fleet']['sk']."',
	fl.fleet_ks AS '".$lang['fleet']['ks']."',
	fl.fleet_recy AS '".$lang['fleet']['recy']."',
	fl.fleet_spio AS '".$lang['fleet']['spio']."',
	fl.fleet_bomb AS '".$lang['fleet']['bomb']."',
	fl.fleet_zer AS '".$lang['fleet']['zer']."',
	fl.fleet_tod AS '".$lang['fleet']['tod']."'
FROM ".$this->sql->getpre()."users us
	LEFT JOIN ".$this->sql->getpre()."planet pl ON pl.user_id=us.user_id
	LEFT JOIN ".$this->sql->getpre()."ally al ON al.ally_id=us.user_ally
	LEFT JOIN ".$this->sql->getpre()."fleet fl ON fl.user_id=us.user_id
	LEFT JOIN ".$this->sql->getpre()."forschung fo ON fo.user_id=us.user_id ".$lines;


$this->sql->query($sql);
$this->sql->fetch_assoc();



echo "<div align=\"center\"><form action=\"\" method=\"post\" name=\"update\"><table width=\"530\">";
$c=1;
foreach($lang['fleet'] as $key=>$value){
	echo "<tr>";
		if($this->user_data['show_bild']==1){
			echo "<td class=\"l\">";
				echo "<img src=\"".$this->user_skin.$lang['fleet_link'][$key]."\" align=\"top\" border=\"0\" height=\"120\" width=\"120\" />";
			echo "</td>";
		}
		
		echo "<td class=\"l\">";
			echo "<strong>".$value."</strong><br />";
			if($this->user_data['show_text']==1)
				echo $lang['fleet_txt'][$key];
		echo "</td>";
		
		echo "<td class=\"k\">";
			if(strlen($this->sql->row[$value])>0){
				if($edit)
					echo "<input ";
				else
					echo "<input readonly=\"true\" ";
				echo "name=\"fleet[$value]\" size=\"6\" maxlength=\"6\" value=\"".$this->sql->row[$value]."\" tabindex=\"$c\">";
			}else
				echo " - ";
		echo "</td>";
	echo "</tr>";
	$c++;
}
if($edit)
	echo "<tr><td class=\"c\" colspan=\"3\" align=\"center\"><input value=\"Absenden\" type=\"submit\"></td></tr>";
echo "</table></form></div>";
?>
